
    var deleteArticleId="";
    var userPhone="";

    $('.superAdminList .superAdminClick').click(function () {
        var flag = $(this).attr('class').substring(16);
        $('#statistics,#articleManagement,#articleComment,#articleCategories,#friendLink,#userFeedback,#privateWord').css("display","none");
        $("#" + flag).css("display","block");
    });

    // 失败消息盒
    function dangerNotice(notice) {
        $('.dangerNotice').html(notice);
        $('.dangerNoticeAlert').css("display","block");
        var closeNoticeBox = setTimeout(function () {
            $('.dangerNoticeAlert').css("display","none");
        },3000);
    }
    // 成功消息盒
    function successNotice(notice) {
        $('.successNotice').html(notice);
        $('.successNoticeAlert').css("display","block");
        var closeNoticeBox = setTimeout(function () {
            $('.successNoticeAlert').css("display","none");
        },3000);
    }
    //填充文章管理
    function putInArticleManagementAdmin(data) {
        var articleManagementTable = $('.articleManagementTable');
        articleManagementTable.empty();
        $.each(data['result'], function (index, obj) {
            articleManagementTable.append($('<tr id="' + obj['articleId'] + '"><td><a href="' + obj['articleUrl'] + '">' + obj['articleTitle'] + '</a></td><td>' + obj['articleDate'] + '</td><td>' + obj['articleCategories'] + '</td> <td>' + obj['articleAuthor'] + '</td><td><span class="am-badge am-badge-success">' + obj['articleHot'] + '</span></td>' +
                '<td>' +
                '<div class="am-dropdown" data-am-dropdown>' +
                '<button class="articleManagementBtn articleEditor am-btn am-btn-secondary">编辑</button>' +
                '<button class="articleDeleteBtn articleDelete am-btn am-btn-danger">删除</button>' +
                '</div>' +
                '</td>' +
                '</tr>'));
        });
        articleManagementTable.append($('<div class="my-row" id="page-father">' +
            '<div id="articleManagementPagination">' +
            '<ul class="am-pagination  am-pagination-centered">' +
            '</ul>' +
            '</div>' +
            '</div>'));

        $('.articleManagementBtn').click(function () {
            var $this = $(this);
            var id = $this.parent().parent().parent().attr("id").substring(0);
            window.location.replace("/article/update/" + id);
        });
        $('.articleDeleteBtn').click(function () {
            var $this = $(this);
            deleteArticleId = $this.parent().parent().parent().attr("id").substring(0);
            $('#deleteAlter').modal('open');
        })
    }
    //删除文章
    $('.sureArticleDeleteBtn').click(function () {
        $.ajax({
            type:'get',
            url:'/article/deleteArticle/'+deleteArticleId,
            dataType:'',
            data:{

            },
            success:function (data) {
                if(data == 0){
                    dangerNotice("删除文章失败")
                } else {
                    successNotice("删除文章成功");
                    getArticleManagementAdmin(1);
                }
            },
            error:function () {
                alert("删除失败");
            }
        });
    })

    //获得文章管理文章
    function getArticleManagementAdmin(currentPage) {
        $.ajax({
            type:'get',
            url:'/findArticle/getArticleManagementAdmin',
            dataType:'json',
            data:{
                rows:10,
                pageNum:currentPage
            },
            success:function (data) {
                putInArticleManagementAdmin(data);
                scrollTo(0,0);//回到顶部

                //分页
                $("#articleManagementPagination").paging({
                    rows:data['pageInfo']['pageSize'],//每页显示条数
                    pageNum:data['pageInfo']['pageNum'],//当前所在页码
                    pages:data['pageInfo']['pages'],//总页数
                    total:data['pageInfo']['total'],//总记录数
                    callback:function(currentPage){
                        getArticleManagementAdmin(currentPage);
                    }
                });
            },
            error:function () {
                alert("获取文章信息失败");
            }
        });
    }

    //填充用户管理
    function putInUserManagement(data) {
        var userManagementTable = $('.userManagementTable');
        userManagementTable.empty();
        $.each(data['result'], function (index, obj) {
            if(obj['role']=="user"){
                userManagementTable.append($('<tr id="'+obj['userphone']+'">'+
                    '<td><a href="">'+obj['username0']+'</a></td>'+
                    '<td>'+obj['birthday']+'</td>'+
                    '<td>'+obj['userphone']+'</td>' +
                    '<td><span class="am-badge am-badge-success" id="userspan">'+obj['role']+'</span></td>' +
                    '<td>'+
                    '<div c=lass="am-dropdown" data-am-dropdown>' +
                    '<button  class="userManagementAdminBtn articleEditor am-btn am-btn-secondary" >设为管理</button>'+
                    '<button class="userDeleteBtn articleDelete am-btn am-btn-danger">删除</button>'+
                    '</div>'+
                    '</td>'+
                    '</tr>'));
            }else {
                userManagementTable.append($('<tr id="'+obj['userphone']+'">'+
                    '<td><a href="">'+obj['username0']+'</a></td>'+
                    '<td>'+obj['birthday']+'</td>'+
                    '<td >'+obj['userphone']+'</td>' +
                    '<td><span class="am-badge am-badge-success" id="adminspan">'+obj['role']+'</span></td>' +
                    '<td>'+
                    '<div c=lass="am-dropdown" data-am-dropdown>' +
                    '<button  class="userManagementUserBtn articleEditor am-btn am-btn-secondary" >设为用户</button>'+
                    '<button class="userDeleteBtn articleDelete am-btn am-btn-danger">删除</button>'+
                    '</div>'+
                    '</td>'+
                    '</tr>'));
            }

        });
        userManagementTable.append($('<div class="my-row" id="page-father">' +
            '<div id="userManagementPagination">' +
            '<ul class="am-pagination  am-pagination-centered">' +
            '</ul>' +
            '</div>' +
            '</div>'));

        //改为用户
        $('.userManagementUserBtn').click(function () {
            var $this = $(this);
            var id = $this.parent().parent().parent().attr("id").substring(0);
            window.location.replace("/adminToUser/" + id);
        });

        //改为管理员
        $('.userManagementAdminBtn').click(function () {
            var $this = $(this);
            var id = $this.parent().parent().parent().attr("id").substring(0);
            window.location.replace("/userToAdmin/" + id);
        });

        //删除用户
        $('.userDeleteBtn').click(function () {
            var $this = $(this);
            userPhone = $this.parent().parent().parent().attr("id").substring(0);
            $('#deleteAlteruser').modal('open');
        })
    }

    //删除用户
    $('.sureUserDeleteBtn').click(function () {
        window.location.replace("/deleteUser/" + userPhone);
    })

    //填充分类管理
    function putInCategoriesManagement(data) {
        var categoriesManagementTable = $('.categoriesManagementTable');
        categoriesManagementTable.empty();
        $.each(data['result'], function (index, obj) {
            categoriesManagementTable.append($('<tr id="'+obj['categoriesName']+'">'+
                '<td><a href="">'+obj['categoriesName']+'</a></td>'+
                '<td>'+obj['categoriesData']+'</td>'+
                '<td>'+obj['categoriesNum']+'</td>' +
                '<td><span class="am-badge am-badge-success">'+obj['categoriesStatus']+'</span></td>' +
                '<td>'+
                '<div c=lass="am-dropdown" data-am-dropdown>' +
                '<button  class="beginCategories articleEditor am-btn am-btn-secondary" >启用</button>'+
                '<button class="stopCategories articleDelete am-btn am-btn-danger">禁用</button>'+
                '</div>'+
                '</td>'+
                '</tr>'));

        });
        categoriesManagementTable.append($('<div class="my-row" id="page-father">' +
            '<div id="categoriesManagementPagination">' +
            '<ul class="am-pagination  am-pagination-centered">' +
            '</ul>' +
            '</div>' +
            '</div>'));

        //启用
        $('.beginCategories').click(function () {
            var $this = $(this);
            var categoriesName = $this.parent().parent().parent().attr("id").substring(0);
            window.location.replace("/categories/categoriesToBegin/" + categoriesName);
        });

        //禁用
        $('.stopCategories').click(function () {
            var $this = $(this);
            var categoriesName = $this.parent().parent().parent().attr("id").substring(0);
            window.location.replace("/categories/categoriesToStop/" + categoriesName);
        });

    }
    //获得用户管理
    function getUserManagement(currentPage) {
        $.ajax({
            type:'get',
            url:'/users/getUserManagement',
            dataType:'json',
            data:{
                rows:5,
                pageNum:currentPage
            },
            success:function (data) {
                putInUserManagement(data);
                scrollTo(0,0);//回到顶部

                //分页
                $("#userManagementPagination").paging({
                    rows:data['pageInfo']['pageSize'],//每页显示条数
                    pageNum:data['pageInfo']['pageNum'],//当前所在页码
                    pages:data['pageInfo']['pages'],//总页数
                    total:data['pageInfo']['total'],//总记录数
                    callback:function(currentPage){
                        getUserManagement(currentPage);
                    }
                });
            },
            error:function () {
                alert("获取文章信息失败");
            }
        });
    }


    //获得分类管理
    function getCategoriesManagement(currentPage) {
        $.ajax({
            type:'get',
            url:'/categories/getCategoriesManagement',
            dataType:'json',
            data:{
                rows:5,
                pageNum:currentPage
            },
            success:function (data) {
                putInCategoriesManagement(data);
                scrollTo(0,0);//回到顶部

                //分页
                $("#categoriesManagementPagination").paging({
                    rows:data['pageInfo']['pageSize'],//每页显示条数
                    pageNum:data['pageInfo']['pageNum'],//当前所在页码
                    pages:data['pageInfo']['pages'],//总页数
                    total:data['pageInfo']['total'],//总记录数
                    callback:function(currentPage){
                        getCategoriesManagement(currentPage);
                    }
                });
            },
            error:function () {
                alert("获取文章信息失败");
            }
        });
    }

    //添加分类
    $('.addCategoriesButton').click(function () {
        $('#addCategories').modal('open');
    })

    //确认添加分类
    $('.sureAddCategories').click(function () {
        var catagories =$("#categoriesValue").val();
        $.ajax({
            type:'get',
            url:'/categories/addCategories',
            dataType:'',
            data:{
                categoriesName:catagories
            },
            success:function (data) {
                if(data=="添加成功"){
                    successNotice("添加成功");
                    getCategoriesManagement(1);
                }else if(data=="已经存在"){
                    dangerNotice("该分类已经存在");
                }else {
                    dangerNotice("添加失败");
                }

            },
            error:function () {
                alert("添加分类失败");
            }
        });
    })

    //点击相册管理
    $('.leaveMessage').click(function () {
        $("#Images li img").height($("#Images li img").width());
    });
    //点击文章管理
    $('.superAdminClick').click(function () {
        getArticleManagementAdmin(1);
    });
    //点击分类管理
    $('.articleComment').click(function () {
        getCategoriesManagement(1);
    });

    //获取用户管理
    getUserManagement(1);